﻿#include "CPacket.h"

#include "../Utils/Utils.h"

int C_Packet::getId() {
	return Utils::Utils::CallVFunc<1, int>(this);
}

TextHolder* C_Packet::getName() {
	return Utils::Utils::CallVFunc<2, TextHolder*>(this, new TextHolder());
}

LevelSoundEventPacket::LevelSoundEventPacket() {
	static uintptr_t** LevelSoundEventPacketVtable = 0x0;
	if (LevelSoundEventPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 8183066;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		LevelSoundEventPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(LevelSoundEventPacket));  // Avoid overwriting vtable
	vTable = LevelSoundEventPacketVtable;
	this->entityType.setText(u8"minecraft:player");
}

PlayerAuthInputPacket::PlayerAuthInputPacket() {
	static uintptr_t** PlayerAuthInputPacketVtable = 0x0;
	if (PlayerAuthInputPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 24391649;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		PlayerAuthInputPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(PlayerAuthInputPacket));  // Avoid overwriting vtable
	vTable = PlayerAuthInputPacketVtable;
}

PlayerAuthInputPacket::PlayerAuthInputPacket(vec3_t pos, float pitch, float yaw, float yawUnused) {
	static uintptr_t** PlayerAuthInputPacketVtable = 0x0;
	if (PlayerAuthInputPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 24391649;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		PlayerAuthInputPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(PlayerAuthInputPacket));  // Avoid overwriting vtable
	vTable = PlayerAuthInputPacketVtable;
	this->pos = pos;
	this->pitch = pitch;
	this->yaw = yaw;
	this->yawUnused = yawUnused;
	this->num4294967298 = 4294967298;
	this->zero = 0;
	this->one = 1;
	this->two = 2;
	this->counter = 0;
	this->InputAD = 0.f;
	this->InputWS = 0.f;
	for (int i = 0; i < 32; i++) {
		this->padThingy[i] = 0;
	}
	for (int i = 0; i < 12; i++) {
		this->epicpad[i] = 0;
	}
}

C_MobEquipmentPacket::C_MobEquipmentPacket() {
	static uintptr_t** MobEquipmentPacketVtable = 0x0;
	if (MobEquipmentPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 24409386;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		MobEquipmentPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_MobEquipmentPacket));  // Avoid overwriting vtable
	vTable = MobEquipmentPacketVtable;
}

C_MobEquipmentPacket::C_MobEquipmentPacket(__int64 entityRuntimeId, C_ItemStack& item, int hotbarSlot, int inventorySlot) {
	fast_io::freestanding::my_memset(this, 0x0, sizeof(C_MobEquipmentPacket));
	using MobEquimentPacketConstructor_t = void(__fastcall*)(C_MobEquipmentPacket*, __int64, C_ItemStack&, int, int, char);
	static MobEquimentPacketConstructor_t MobEquimentPacketConstructor = reinterpret_cast<MobEquimentPacketConstructor_t>(Utils::Utils::getBase() + 26913456);

	MobEquimentPacketConstructor(this, entityRuntimeId, item, hotbarSlot, inventorySlot, 0);
}

C_InventoryTransactionPacket::C_InventoryTransactionPacket() {
	static uintptr_t** InventoryTransactionPacketVtable = 0x0;
	if (InventoryTransactionPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 24351307;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		InventoryTransactionPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_InventoryTransactionPacket));  // Avoid overwriting vtable
	vTable = InventoryTransactionPacketVtable;
}

C_TextPacket::C_TextPacket() {
	static uintptr_t** textPacketVtable = 0x0;
	if (textPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 16228720;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		textPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_TextPacket));  // Avoid overwriting vtable
	vTable = textPacketVtable;

	messageType = 1;  // TYPE_CHAT
}

C_TextPacket::C_TextPacket(std::u8string_view name, std::u8string_view xboxid) {
	static uintptr_t** textPacketVtable = 0x0;
	if (textPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 16228720;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		textPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_TextPacket));  // Avoid overwriting vtable
	vTable = textPacketVtable;

	messageType = 1;  // TYPE_CHAT
	sourceName.setText(name);
	xboxUserId.setText(xboxid);
}

C_TextPacket_view::C_TextPacket_view(std::u8string_view name, std::u8string_view xboxid) {
	static uintptr_t** textPacketVtable = 0x0;
	if (textPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 16228720;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		textPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_TextPacket));  // Avoid overwriting vtable
	vTable = textPacketVtable;

	messageType = 1;  // TYPE_CHAT
	sourceName.setText(name);
	xboxUserId.setText(xboxid);
}
C_MovePlayerPacket::C_MovePlayerPacket() {
	static uintptr_t** movePlayerPacketVtable = 0x0;
	if (movePlayerPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 16061731;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_MovePlayerPacket));  // Avoid overwriting vtable
	vTable = movePlayerPacketVtable;
}

C_MovePlayerPacket::C_MovePlayerPacket(C_LocalPlayer* player, vec3_t pos) {
	static uintptr_t** movePlayerPacketVtable = 0x0;
	if (movePlayerPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 16061731;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		movePlayerPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_MovePlayerPacket));  // Avoid overwriting vtable
	vTable = movePlayerPacketVtable;
	entityRuntimeID = player->entityRuntimeId;
	Position = pos;
	pitch = player->pitch;
	yaw = player->yaw;
	headYaw = player->yaw;
	onGround = true;
	mode = 0;
}

C_PlayerActionPacket::C_PlayerActionPacket() {
	static uintptr_t** playerActionPacketVtable = 0x0;
	if (playerActionPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 14216061;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		playerActionPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_PlayerActionPacket));  // Avoid overwriting vtable
	vTable = playerActionPacketVtable;
}

C_SubChunkRequestPacket::C_SubChunkRequestPacket() {
	static uintptr_t** subChunkRequestPacketVtable = 0x0;
	if (subChunkRequestPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 24873498;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		subChunkRequestPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_SubChunkRequestPacket));  // Avoid overwriting vtable
	vTable = subChunkRequestPacketVtable;
}

C_EmotePacket::C_EmotePacket() {
	static uintptr_t** emotePacketVtable = 0x0;
	if (emotePacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 14220095;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		emotePacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_EmotePacket));  // Avoid overwriting vtable
	vTable = emotePacketVtable;
}

C_AnimatePacket::C_AnimatePacket() {
	static uintptr_t** animatePacketVtable = 0x0;
	if (animatePacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 25877159;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		animatePacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_AnimatePacket));  // Avoid overwriting vtable
	vTable = animatePacketVtable;
}
/*
C_AnimatePacket::C_AnimatePacket(AnimatePacket Action, __int64 entityRuntimeId, float) {
}
*/

C_NPCRequestPacket::C_NPCRequestPacket() {
	static uintptr_t** npcRequestPacketVtable = 0x0;
	if (npcRequestPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 26918099;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		npcRequestPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_NPCRequestPacket));  // Avoid overwriting vtable
	vTable = npcRequestPacketVtable;
}

PlayerSkinPacket::PlayerSkinPacket() {
	static uintptr_t** playerSkinPacketVtable = 0x0;
	if (playerSkinPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 27075379;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		playerSkinPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(PlayerSkinPacket));  // Avoid overwriting vtable
	vTable = playerSkinPacketVtable;
}

NetworkLatencyPacket::NetworkLatencyPacket() {
	static uintptr_t** networkLatencyPacketVtable = 0x0;
	if (networkLatencyPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 24320817;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		networkLatencyPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(NetworkLatencyPacket));  // Avoid overwriting vtable
	vTable = networkLatencyPacketVtable;
}

CommandRequestPacket::CommandRequestPacket() {
	static uintptr_t** commandRequestPacketVtable = 0x0;
	if (commandRequestPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 24392596;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		commandRequestPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(CommandRequestPacket));  // Avoid overwriting vtable
	vTable = commandRequestPacketVtable;
}

CommandRequestPacket::CommandRequestPacket(std::u8string_view cmd, uint8_t t) {
	static uintptr_t** commandRequestPacketVtable = 0x0;
	if (commandRequestPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 24392596;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		commandRequestPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(CommandRequestPacket));  // Avoid overwriting vtable
	vTable = commandRequestPacketVtable;
	command.setText(cmd);
	type = t;
}

C_InteractPacket::C_InteractPacket(/*enum InteractPacket::Action, class ActorRuntimeID, vec3_t const&*/) {
	static uintptr_t** interactPacketVtable = 0x0;
	if (interactPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 24348619;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		interactPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(C_InteractPacket));  // Avoid overwriting vtable
	vTable = interactPacketVtable;
}

ActorEventPacket::ActorEventPacket(uint64_t entityRuntimeId, char eventId, int16_t itemId) {
	static uintptr_t** actorEvenPacketVtable = 0x0;
	if (actorEvenPacketVtable == 0x0) [[unlikely]] {
		uintptr_t sigOffset = Utils::Utils::getBase() + 14214552;
		int offset = *reinterpret_cast<int*>(sigOffset + 3);
		actorEvenPacketVtable = reinterpret_cast<uintptr_t**>(sigOffset + offset + /*length of instruction*/ 7);
	}
	fast_io::freestanding::my_memset(this, 0, sizeof(ActorEventPacket));  // Avoid overwriting vtable
	vTable = actorEvenPacketVtable;
	this->two = 2;
	this->one = 1;
	this->entityRuntimeId = entityRuntimeId;
	this->eventId = eventId;
	this->itemId = itemId;
}
